#include <ace/Message_Block.h> 

#include "TaskThread.h"

static int threadIndex = 0;

int TaskThread::svc()
{
	threadIndex++;
	ACE_Message_Block *mb = 0;
	char flag[100] ={0};
	sprintf(flag,"Thread_Task: <%d>,ThreadID: <%ld>",threadIndex,ACE_Thread::self());
	while(1)
	{
		ACE_Time_Value nowait (ACE_Time_Value::zero);
		this->getq(mb,&nowait);
		if(0 != mb)
		{
			char * data = mb->rd_ptr();
			if(strncmp(data,"Close",6) == 0)
			{
				printf("Thread_Task <%s> will exit.\n",flag);
				return -1;
			}
		}
		printf("Thread_Task Heart Beat:(%s)\n",flag);
		Sleep(2000);
	}

	return 0;
}

// The last chance to cleanup this class
int TaskThread::close(u_long  flags )
{
	printf("Exiting Thread_Task: <%d>,ThreadID: <%ld>",threadIndex,ACE_Thread::self());
	return 0;
}